home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / noweb / nwsrcfilter.icn < prev    next >
Text File  |  1995-02-24  |  1KB  |  61 lines

  1. # nwsrcfilter -- filter out irrelevant files, put .nw files first
  2.  
  3. procedure main(args)
  4.   while line := read() do
  5.     if not (line[-1] == "~" | line == "." | find("/RCS", line) |
  6.             (line ? (tab(find("./binaries/")), move(1))) |
  7.             line[3] == line[-1] == "#" | line == "./nwsrcfilter") then 
  8.       line ? (="./" & save_file(tab(0)))
  9.   dump_files()
  10. end
  11.  
  12. global root
  13.  
  14. global files_in_input
  15.  
  16. procedure save_file(name)
  17.   initial {root := table(); files_in_input := set()}
  18.   insert(files_in_input, name)
  19.   name ? do_save(root)
  20.   return
  21. end
  22.  
  23. procedure do_save(root)
  24.   if key := tab(upto('/')) & tab(many('/')) then {
  25.     /root[key] := table()
  26.     do_save(root[key])
  27.   } else
  28.     /root[tab(0)] := table()
  29. end
  30.  
  31. procedure dump_files(prefix, r)
  32.   /prefix := ""
  33.   /r := root
  34.   if *r = 0 then return
  35.   l := sort(r)
  36.   bubblenw(l)
  37.   every p := !l do
  38.     if *p[2] > 0 then {
  39.       dump_files(prefix || p[1] || "/", p[2])
  40.       if member(files_in_input, prefix || p[1]) then write(prefix, p[1])
  41.         # only dump directories if they were given explicitly
  42.     } else {
  43.       write(prefix, p[1])
  44.     }
  45. end
  46.  
  47. procedure bubblenw(l)
  48.   lo := 1    # first non-nw
  49.   while l[lo][1][-3:0] == ".nw" do lo +:= 1
  50.   hi := lo +1    # first succeeding nw
  51.   while l[hi][1][-3:0] ~== ".nw" do hi +:= 1
  52.   while hi <= *l do {
  53.     i := hi
  54.     while i > lo do {l[i] :=: l[i-1]; i -:= 1}
  55.     lo +:= 1
  56.     hi +:= 1
  57.     while l[hi][1][-3:0] ~== ".nw" do hi +:= 1
  58.   }
  59.   return l
  60. end
  61.